<script setup>

import {pageofficeOpenFile} from "@/plugins/pageoffice/pageoffice-common.js";
import {backMyDocList} from "@/utils/backList.js";
import {
  distributeComplete,
} from "@/api/document/myDocument.js";
import AdviceList from "@/views/document/common/advice/adviceList.vue";
import CancelButton from "@/views/document/my/flowInfo/common/cancelButton.vue";

const {proxy} = getCurrentInstance()
const loading = ref(false)
const emits = defineEmits(['loadMainViewData'])
const prop = defineProps({
  docId: {
    type: Number
  },
  flowInfoButtons: {
    type: JSON
  },
  isRefreshAdvice: {
    type: Boolean
  }
})

function openFinalFile() {
  pageofficeOpenFile('/document/my/common/openFinalFile/' + prop.docId, prop.docId)
}

function refreshMainViewData() {
  loading.value = false
  emits("loadMainViewData")
}

function handleNext() {
  proxy.$modal.confirmAndExecuteJS('确认公文要分发办结？', distributeComplete, prop.docId, refreshMainViewData)
}

</script>

<template>
  <el-row v-loading="loading" element-loading-text="正在执行，请稍后...">
    <el-col :span="12" class="left">
      <el-row>
        <el-form-item>
          <el-button @click="backMyDocList">返 回</el-button>
          <el-button type="primary" @click="openFinalFile">打开正文</el-button>
          <el-button type="success" @click="handleNext" v-if="flowInfoButtons.isNext">分发并办结</el-button>
        </el-form-item>
      </el-row>
    </el-col>
    <el-col :span="12">
      <el-row justify="end">
        <el-form-item>
          <CancelButton :docId="docId" :isCancel="flowInfoButtons.isCancel"/>
        </el-form-item>
      </el-row>
    </el-col>
  </el-row>
  <AdviceList :isRefreshAdvice="isRefreshAdvice"/>
</template>

